<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport" />
    <meta content="yes" name=" apple-mobile-web-app-capable" />
    <!-- 隐藏状态栏  -->
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
    <!-- <title>支付成功</title> -->
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/details.css">
</head>

<body class="ng-cloak" ng-app="CheerHiWx" ng-controller="OkPayCtrl">
    <header>
        <div class="finish wrapper clearfix">
            <div class="fr">
                <a href="index.html" class="login_icon">完成</a>
            </div>
            <h1>支付成功</h1>
        </div>
    </header>
    <section>
        <div class="order_content com_step p10">
            <h1><i></i>付款成功，房间已为您保留</h1>
            <p class="goodname"><span>商品名称:</span> {{params.tradeName}}</p>
            <p class="order_num"> <span>订单号:</span>{{params.orderNum}} <a href="order-details.html?orderNum={{params.orderNum}}"> 查看订单 
      </a></p>
        </div>
    </section>

    <!-- 发红包 -->
    <div class="send-gift" ng-if="showcode">
        <img src="img/send_gift.png" alt="" data-toggle="modal" data-target="#share">
    </div>

    <!-- 获得红包模态框 -->
    <div class="modal fade" id="coupon" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content" id="c15-modal">
                <div class="modal-body clearfix">
                    <div class="text-center">
                        <h3>获得{{couponDetails.data.size}}个红包</h3>
                        <div class="get-coupon">
                            <ul class="text-center">
                                <li class="clearfix" ng-repeat="couponInfo in couponDetails.data.list">
                                    <div class="coupon-info">
                                        <div>
                                            <p>{{couponInfo.ticketValue}}</p>
                                        </div>
                                        <div>
                                            <p>{{couponInfo.couponName}}</p>
                                            <p class="available">满{{couponInfo.useExceedValue}}元使用</p>
                                            <!-- <p>已使用</p> -->
                                            <small>{{couponInfo.useTimeStart}}至{{couponInfo.useTimeEnd}}</small>
                                        </div>
                                    </div>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">
                        <img src="img/modal-colse.png" alt="">
                        <p>关闭</p>
                    </button>
                </div>
            </div>
        </div>
    </div>
    <!-- 分享页模态框 -->
    <div class="modal fade" id="share" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <img class="arrow_toShare" src="img/arrow_toShare.png" alt="">
        </div>
    </div>
    </div>
</body>

    <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
    <script src="js/jquery-1.11.2.min.js"></script>
    <script src="js/angular.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script type="text/javascript" src="js/constants.js"></script>
    <script src="js/common.js"></script>
    <script>
    //获取订单详细
    var urlOrderDetail = server_host + '/userweb/getUserOrderDetail.do';
    // 分享接口
    var urlCreateShareCoupon = server_host + '/uweb/coupon/order/createShareCoupon.do';
    var params = getParameterByName('params');
    // 取shopId
    var shopId = sessionStorage.getItem('shopId');
    // 是否有红包
    var urlHasCoupon = server_host + '/uweb/coupon/seekConsumeCoupon.do';

    // 红包列表
    var userCouponList = server_host + '/uweb/coupon/userCouponList.do?useType=0';

    var orderNum;

    var appModule = angular.module('CheerHiWx', []);
    appModule.controller('OkPayCtrl', ['$scope', '$http', function($scope, $http) {

        $scope.showcode = false;

        if (shopId == 90 || shopId == 91 || shopId == 92) {
            orderNum = getParameterByName('orderNum');
            // 获取页面数据（跳过支付）
            $scope.loadOrderDetail = function() {
                $http.get(urlOrderDetail + '?orderNum=' + orderNum).success(function(data, status, headers, config) {
                    $scope.orderDetails = data.data;
                });
            }
                // 红包（跳过支付）
            $scope.loadCoupon = function() {
                $http.get(urlHasCoupon + '?orderNum=' + orderNum).success(function(data, status, headers, config) {
                    console.log(data);
                    $scope.couponDetails = data;
                    console.log(data);
                    var code = $scope.couponDetails.code;
                    if (code == 0) {
                        // 弹出框
                        $('#coupon').modal({
                            show: true,
                            backdrop: true
                        });
                    }
                });
            }

        } else {
            // 原来正确流程 区别：orderNum获取方式不同 $scope.params.orderNum
            $scope.params = eval('(' + decodeURIComponent(atob(params)) + ')');
            orderNum = $scope.params.orderNum;
            $scope.loadOrderDetail = function() {
                $http.get(urlOrderDetail + '?orderNum=' + $scope.params.orderNum).success(function(data, status, headers, config) {
                    $scope.orderDetails = data.data;
                });
            }
                // 红包（正常支付）
            $scope.loadCoupon = function() {
                $http.get(urlHasCoupon + '?orderNum=' + $scope.params.orderNum).success(function(data, status, headers, config) {
                    $scope.couponDetails = data;
                    console.log(data);
                    var code = $scope.couponDetails.code;
                    if (code == 0) {

                        $('#coupon').modal({
                            show: true,
                            backdrop: true
                        });
                    }
                });
            }
        }

        $scope.loadOrderDetail();
        $scope.loadCoupon();
        // $scope.loadShareCoupon();
    }]);

    // 微信分享
    function wxJssdkInit() {
        $.ajax({
            type: 'POST',
            dataType: 'json',
            url: server_host + '/h5wx/getWxTicket.do?url=' + encodeURIComponent(location.href.split('#')[0]),
            success: function(data) {

                wx.config({
                    debug: false,
                    appId: wxAppId,
                    timestamp: data.timestamp,
                    nonceStr: data.nonceStr,
                    signature: data.signature,
                    jsApiList: wxJsApi
                });

                $.ajax({
                    type: 'GET',
                    dataType: 'json',
                    url: urlCreateShareCoupon + '?orderNum=' + orderNum,
                    success: function(data) {

                        angular.element(document.body).scope().showcode = (data.code == 0);
                        angular.element(document.body).scope().$apply();

                        // var shareDetailsInfo = angular.element(document.body).scope().shareDetails.data;
                        console.log(data);

                        wx.onMenuShareAppMessage({
                            title: data.data.title, // 分享标题
                            desc: data.data.context, // 分享描述
                            link: data.data.shareUrl, // 分享链接
                            imgUrl: data.data.img, // 分享图标
                            type: 'link', // 分享类型,music、video或link，不填默认为link
                            dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
                            success: function() {
                                alert('分享成功！');
                            },
                            cancel: function() {
                                // 用户取消分享后执行的回调函数
                            }
                        });
                        wx.onMenuShareTimeline({
                            title: data.data.title, // 分享标题
                            link: data.data.shareUrl, // 分享链接
                            imgUrl: data.data.img, // 分享图标
                            success: function() {
                                alert('分享成功！');
                            },
                            cancel: function() {
                                // 用户取消分享后执行的回调函数
                            }
                        });
                        wx.onMenuShareQQ({
                            title: data.data.title, // 分享标题
                            desc: data.data.context, // 分享描述
                            link: data.data.shareUrl, // 分享链接
                            imgUrl: data.data.img, // 分享图标
                            success: function() {
                                alert('分享成功！');
                            },
                            cancel: function() {
                                // 用户取消分享后执行的回调函数
                            }
                        });


                    }

                })
            }
        });
    }
    if (typeof WeixinJSBridge == "undefined") {
        if (document.addEventListener) {
            document.addEventListener('WeixinJSBridgeReady', wxJssdkInit, false);
        } else if (document.attachEvent) {
            document.attachEvent('WeixinJSBridgeReady', wxJssdkInit);
            document.attachEvent('onWeixinJSBridgeReady', wxJssdkInit);
        }
    } else {
        wxJssdkInit();
    }
    
    </script>
<span style="display:none;"><script type="text/javascript">var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");document.write(unescape("%3Cspan id='cnzz_stat_icon_1255764485'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s95.cnzz.com/z_stat.php%3Fid%3D1255764485%26show%3Dpic1' type='text/javascript'%3E%3C/script%3E"));</script></span>
<script>
    _maq.push(['_setMaq', 'ok-pay']);
</script>
</html>
</html>
